<!DOCTYPE HTML>
<script src="../../resources/ahem.js"></script>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="../assert_selection.js"></script>
<script>
const isMac = navigator.platform.indexOf('Mac') === 0;

function dragOverBlocks(selection, offsetTopToDestination) {
  const document = selection.document;
  const divlist = document.querySelectorAll('p');
  const div0 = divlist[0];
  const div1 = divlist[1];
  eventSender.mouseMoveTo(document.offsetLeft + div0.offsetLeft,
                          document.offsetTop + div0.offsetTop + 5);
  eventSender.mouseDown();
  eventSender.mouseMoveTo(document.offsetLeft + div1.offsetLeft + 40,
                          document.offsetTop + div1.offsetTop
                          + offsetTopToDestination);
  eventSender.mouseUp();
}

const kStyle = '<style>* { font: 20px Ahem; }</style>';

selection_test(
    [kStyle, '<p>AAAAA</p><p>BBBBB</p>'],
    selection => dragOverBlocks(selection, -20),
    [kStyle, '<p>^AA|AAA</p><p>BBBBB</p>'],
    'Continuations across a block -20');

selection_test(
    [kStyle, '<p>AAAAA</p><p>BBBBB</p>'],
    selection => dragOverBlocks(selection, -15),
    [kStyle,
    isMac
    ? '<p>^AAAAA</p><p>|BBBBB</p>'
    : '<p>^AAAAA</p><p>BB|BBB</p>'
    ],
    'Continuations across a block -15');

selection_test(
    [kStyle, '<p>AAAAA</p><p>BBBBB</p>'],
    selection => dragOverBlocks(selection, 5),
    [kStyle,'<p>^AAAAA</p><p>BB|BBB</p>'],
    'Continuations across a block 5');
</script>
